<?php

 namespace Admin\Controller;
 use Think\Controller;

  class ArticleController extends PublicController

  {

    public function index(){

     // 实例化model
     //  $model = M();
      // 查询
    //  $data = $model->query('select u.username,a.title,a.content from lamp_user u,lamp_article a where u.id = a.uid');
      // dump($data);

  // 方法2 table 方法

 /*   $data = $model->field('u.username,a.title,a.content')->where('u.id = a.uid')->table('__USER__ u,__ARTICLE__ a')->select();

    dump($data);
*/
 
 // 方法3 查询每一个用户对应的文章数
    // 原生态
  /*  $data = $model->query('select u.username,count(a.id) as total from lamp_user u,lamp_article a where u.id = a.uid group by u.id ');*/
    

   /*$data = $model->query('select u.username,count(a.id) as total from lamp_user u left join lamp_article a on u.id = a.uid group by u.id');*/
     $model = M('user');
   $data = $model->field('u.username,count(a.id) as total')->join('u left join __ARTICLE__ a on u.id = a.uid')->group('u.id')->select();

    // dump($data);
    }

    public function demo()

    {

       $this->display();

    }

    public function demo1()

    {
        dump($_POST);

      // dump(I('post.')); exit;

      // 1。实例化model

       $article = M('article');
    	// dump($article);


        // 2.创建一个安全的数据信息(I函数的功能包含进来)
        $res = $article->create();

    //  dump($res);

     if($res){
       
        $result = $article->add();

        if($result){
          
          echo 'yes';
        }else{
          
          echo 'no';
        }

     }else{
      
        echo $article->getError();   

     }   
    }

   public function show()

   {
     
     $article =M('article');
    // dump($article);
     $data = $article->find(12);

     $this->assign('data',$data);
     $this->display();


     
   }


   


  }
